package com.kgc.bigdata.spark.core

import org.apache.spark.{SparkConf, SparkContext}

/**
  * 作业：使用Spark Core完成用户访问量Top5统计
  */
object PageViewsApp {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf
    sparkConf.setAppName("WordCount")
    val sc = new SparkContext(sparkConf)

    val page_views = sc.textFile("..../page_views.dat")
    page_views.map(_.split("\t")).map(line => (line(5), 1))
      .reduceByKey(_ + _).map(x => (x._2, x._1))
      .sortByKey(false).map(x => (x._2, x._1))
      .take(5).foreach(println)
    sc.stop()
  }
}
